package com.zwh.consumer;


import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;

@Service
/**
 * 有当myapp.environment属性的值是"dev"或"test"时才会生效。
 */
@ConditionalOnExpression("'${myapp.environment}' == 'dev' || '${myapp.environment}' == 'test'")
@RocketMQMessageListener(topic = "testTopic", consumerGroup ="test_group",
//        selectorType = SelectorType.TAG, //选择tag过滤模式
//        selectorExpression = "tageA || tagB", //选择tag
        consumeMode = ConsumeMode.ORDERLY, // ConsumeMode.ORDERLY 顺序消费模式，单线程   ConsumeMode.CONCURRENTLY 并行处理,多线程
        messageModel = MessageModel.BROADCASTING, // 消息模型 MessageModel.CLUSTERING 集群 MessageModel.BROADCASTING 广播
        consumeTimeout = 3000, // 超时时间 默认值 30000ms
        maxReconsumeTimes = 5 //重试次数
)
public class TestConsumer implements RocketMQListener<MessageExt> {

    /**
     * 这个方法就是消费者的方法
     * 如果泛型制定了固定的类型，那么消息体就是我们的参数
     * MessageExt 类型是消息的所有内容
     * @param s
     */
    @Override
    public void onMessage(MessageExt s) {
        System.out.println(s);
    }
}
